home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / spellf.arc / SPELLF.DOC < prev   
Text File  |  1989-10-30  |  19KB  |  404 lines

  1.  
  2. ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
  3. ^                                                                   ^ 
  4. ^    DOCUMENTATION FOR                                              ^ 
  5. ^                                                                   ^ 
  6. ^    SPELLF   !Tiny Trainable Spellfilter  Ver. 1.01                ^ 
  7. ^                                                                   ^ 
  8. ^    (c) 1989 Kas & Rita Thomas. All rights reserved.               ^ 
  9. ^                                                                   ^ 
  10. ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
  11.  
  12. You may distribute SPELLF to your friends.   But if you do so,  please 
  13. register   your copy with us today,  by sending $10  (in cash,  check, 
  14. M.O.,  stamps,  whatever) to: Kas & Rita Thomas, 578  Fairfield  Ave.,
  15. Stamford, CT 06902. 
  16.  
  17. This  program  was created using Borland Turbo C (Ver.  2.0).  If  you 
  18. would like fully commented source code for SPELLF,  kindly send $25 in 
  19. lieu of the registration fee. In other words: For $25,  you get source 
  20. code AND registration, all in one shot (on disk). 
  21.  
  22. When  you  write,  please tell us about your computer setup.  Are  you 
  23. using SPELLF on a laptop?  Which model? (Are you happy with it?)  We'd 
  24. be delighted to hear from you. Write to us today! 
  25.  
  26.  
  27.  
  28.  
  29.  
  30. WHAT IS SPELLF? AND: WHAT ISN'T IT? 
  31.  
  32. SPELLF is a spellfilter. We feel this word better describes the spirit 
  33. of this utility than the term "spellchecker,"  which implies a literal 
  34. brute-force comparison of words against a dictionary.  SPELLF does not 
  35. do this,  obviously. (The "dictionary"  file used by SPELLF is only 8K 
  36. in  size!)  Rather  than check literal spellings,  SPELLF  checks  the 
  37. "legality"  of substrings  within each word and reports out any  words 
  38. that  contain illegal letter combinations.  In this way,  SPELLF  acts 
  39. more  like a logical filter than a mere word-looker-upper.  You give a 
  40. text file to SPELLF, and the program acts as a sieve, reading the text 
  41. file  in and passing suspect words to "stdout"  (the  standard  output 
  42. device  for your computer;  usually the console).  The output is fully 
  43. redirectable,  which means you can have it show up on your printer (or 
  44. on disk) rather than on your screen. 
  45.  
  46. SPELLF carries out its filtering at lightning speed: On the slowest 8-
  47. MHz XT clone we could find, SPELLF took only 10  seconds to spellcheck 
  48. a  120K  text  file!  (It adds words to the  main  dictionary  at  the 
  49. blistering  rate  of 1,000   English words --  about 6 Kbytes  --  per 
  50. second.) On a 286 or 386 machine, you may see throughput rates five to 
  51. ten  times  higher.  Especially if you use redirection.  (The  biggest 
  52. runtime bottleneck for SPELLF is waiting for the screen to update.) 
  53.  
  54. Speed  isn't SPELLF's primary virtue,  however.  Small size  (both  in 
  55. terms of disk image and RAM overhead)  is where SPELLF really  shines. 
  56. The program itself is just 12K,  making it perfect for use on  floppy-
  57. disk-only  systems  (laptops,  for example)  and  systems  that  can't 
  58. accommodate the 200K spellcheckers that come with such programs as ...
  59. well,  you  know  the big names.  At  runtime,  SPELLF  uses  approxi-
  60. mately   76K  of  RAM (12K of core RAM and 64K of  "far  core"    heap 
  61. space).  For its dictionary,  SPELLF uses a disk file only 8 kilobytes 
  62. in size.  No matter how many words you stuff into this dictionary file 
  63. ($.DIC), it never gets bigger than precisely 8K. 
  64.  
  65. Another  virtue  of SPELLF is that it operates in  command-line  mode, 
  66. making it easy to invoke spellchecking from batch files. 
  67.  
  68. And,  SPELLF's  output  (a list  of  suspect words,  with  their  line 
  69. locations in the original file) is redirectable. That is, you can make 
  70. the  suspect-word  list show up at your printer,  or in a new file  on 
  71. disk, rather than on the screen. (Again, this approach lends itself to 
  72. batch file applications.) 
  73.  
  74.  
  75.  
  76.  
  77.  
  78. DISCLAIMERS
  79.  
  80. Whether or not you send us money,  no warranties are made with respect 
  81. to the program's performance, fitness, hardware compatibility, etc. 
  82.  
  83. To run this program, you need at least 72K of free RAM and 20K of disk 
  84. space at all times. Any version of DOS should be fine.
  85.  
  86. Note: This program is designed to spellcheck standard ASCII text files 
  87. only.   Nothing disastrous will happen if you attempt to spellcheck  a 
  88. WordStar file.  SPELLF  merely   ignores   high-bit   characters.  For 
  89. this  reason,  control codes that  fall outside  the  normal  range of  
  90. alpha-numeric  ASCII  characters  pose  no problem whatsoever. But  if 
  91. your  word  processor  uses /b or /i for font  calls,  you   may   see 
  92. erroneous  exception-word  callouts  on  the  screen.   
  93.  
  94. If  there is sufficient demand,  we will rewrite the program  to  take 
  95. care of format code detection. (Don't hold your breath, however!) 
  96.  
  97.  
  98.  
  99.  
  100.  
  101. THE $.DIC FILE 
  102.  
  103. Your  program  should have come bundled with an 8K file called  $.DIC. 
  104. SPELLF  looks  for this file at runtime;  it contains the  information 
  105. needed to conduct spellchecking (or spellfiltering)  operations.  This 
  106. file  MUST be present in the current working directory,  for SPELLF to 
  107. work properly. 
  108.  
  109. The  $.DIC  dictionary  file that we created for  bundling  with  this 
  110. program contains data for 20,000  commonly used English words.  If you 
  111. did not get a copy of $.DIC,  don't panic:  SPELLF will let you create 
  112. your  own $.DIC file,  but you will have to supply your own core  word 
  113. list  (of  properly spelled words)  with  which to make the  file.  To 
  114. create a brand-new $.DIC file from scratch, do this: 
  115.  
  116. 1.  Be sure you are in a directory that contains no $.DIC file.  (If a 
  117. $.DIC file already exists, rename or delete it; otherwise the existing 
  118. file will be UPDATED to contain the new word list.) 
  119.  
  120. 2. Run SPELLF with two arguments as follows: 
  121.  
  122.  
  123.                SPELLF  {filename of word list} -a   [Enter] 
  124.  
  125.  
  126. Don't forget the "-a"  on the command line.  This tells SPELLF to  ADD 
  127. the contents of {filename} to $.DIC. 
  128.  
  129. If $.DIC did not exist before,  a new file named $.DIC will show up in 
  130. your  current directory when you follow the above procedure.  You will 
  131. then be able to "spellcheck" any file against the $.DIC dictionary. 
  132.  
  133. If a $.DIC file already existed in the current directory, the contents 
  134. (vocabulary) of {filename} will simply be ADDED to $.DIC. The previous 
  135. contents of $.DIC will be preserved. It is a true ADD operation. 
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. CREATING CUSTOM DICTIONARIES 
  143.  
  144. Obviously, you can use the foregoing procedure to create any number of 
  145. custom  dictionaries (scientific word lists,  lists of foreign  words, 
  146. computer terms, etc.) for use with the SPELLF program. All you need to 
  147. do  is supply the name of a file containing a list of scientific terms 
  148. (or whatever) on the command line: 
  149.  
  150.  
  151.                   SPELLF NEWWORDS.TXT -a  [Enter] 
  152.  
  153.  
  154. In  this case,  the vocabulary of NEWWORDS.TXT will be added to $.DIC. 
  155. (Once  again:  If $.DIC did not already  exist in the current  working 
  156. directory, it will be created. If it exists, it will be updated.)  The 
  157. filename  does not have to have a .TXT extension;  this is  merely  an 
  158. example.  Any extension is permissible. (Caution:  If you accidentally 
  159. supply the name of a spreadsheet or other non-text file,  you stand  a 
  160. chance  of corrupting your existing $.DIC file.  Always keep a  "good" 
  161. copy of $.DIC on a backup disk somewhere.) 
  162.  
  163. Note  that SPELLF is not merely an  English-language spellchecker.  If 
  164. you  happen  to have a French word list on disk,  you can  use  it  to 
  165. create a French-language version of $.DIC, and hence a French-language 
  166. spellchecker. The copy of $.DIC that comes bundled with SPELLF happens 
  167. to  contain  20,000  English words.  It could just as  easily  contain 
  168. French, Spanish, German, or Italian words, etc. 
  169.  
  170.  
  171.  
  172.  
  173.  
  174. SPELLCHECKING 
  175.  
  176. To  spellcheck  a text file,  just type SPELLF at the DOS  prompt  and 
  177. supply the name of the text file you wish to examine.  Then hit Enter. 
  178. Example: 
  179.  
  180.  
  181.                     SPELLF {filename} [Enter] 
  182.  
  183.  
  184.  
  185. If  you  type SPELLF DRAFT.DOC [Enter],  the file  DRAFT.DOC  will  be 
  186. rigorously spell-checked using the words contained in $.DIC. (Remember 
  187. that  SPELLF  expects the file $.DIC to be in the  same  directory  as 
  188. DRAFT.DOC.)  A complete list of suspect words and their line locations 
  189. will be printed to the screen. If you want,  the list of suspect words 
  190. can  show  up  in a separate disk file,  or be  printed  out  on  your 
  191. printer. This is called redirection. 
  192.  
  193. To  redirect the output of SPELLF to a brand-new file called BADWORDS, 
  194. simply type: 
  195.  
  196.  
  197.  
  198.                  SPELLF  DRAFT.DOC > BADWORDS [Enter] 
  199.  
  200.  
  201.  
  202. During  program execution,  in this case,  nothing will happen on  the 
  203. screen (but the disk will be active). When the DOS prompt returns, you 
  204. should  see  that  there is a new  file,  BADWORDS,  in  your  current 
  205. directory. You can look at this file with the DOS command TYPE, or use 
  206. your favorite word processor to open it. 
  207.  
  208. Note  that SPELLF operates much faster when redirection to a  file  is 
  209. used.  That's because the process of  displaying output on the  screen 
  210. (in  SPELLF's default mode)  is inherently slow --  slower,  at least, 
  211. than SPELLF's file I/O operations. 
  212.  
  213. You may wish, occasionally, to redirect output to your printer. Again, 
  214. you can use DOS to do this: 
  215.  
  216.  
  217.  
  218.                  SPELLF  DRAFT.DOC  > PRN  [Enter] 
  219.  
  220.  
  221. This  causes  the  file DRAFT.DOC to be spellchecked and  the  suspect 
  222. words to appear at the printer, rather than at the screen. 
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229. TESTING WORDS FOR PRESENCE IN THE DICTIONARY 
  230.  
  231. You  can  test  words  for presence or absence in  the dictionary. 
  232. The procedure is very simple: Just type SPELLF and -t.  Like this:
  233.  
  234.  
  235.  
  236.                          SPELLF -t  [Enter] 
  237.  
  238.  
  239.  
  240. As soon as the program loads,  a  query message comes up on the screen 
  241. asking  you to supply a word.  Just  type it on the screen;  then  hit 
  242. Enter.  SPELLF  will consult $.DIC to  see if the word  you  typed  is 
  243. already in the dictionary.  If it is, you'll be told so,  and you will 
  244. be  asked  if you want to test another word.  (Type 'y'  or  Enter  to 
  245. answer  in  the affirmative.)  If the word you typed was  NOT  in  the 
  246. dictionary,  you'll be told so,  and you will be given a chance to add 
  247. it.  No extra typing is required to add  the word:  Just hit Enter  OR 
  248. type 'y'  for yes.  (You must type 'n'  if you do NOT wish to add  the 
  249. word to $.DIC.) 
  250.  
  251. You  may keep checking words in this fashion for as long as you  like. 
  252. The  loop  will stop when you answer 'n'  (No)  to the  "Test  another 
  253. word?" prompt. 
  254.  
  255. "Test"  mode  thus  offers a  second  way  (besides  "Add"  mode;  see 
  256. "CREATING CUSTOM DICTIONARIES,"  above) to update the dictionary.  You 
  257. can update the $.DIC dictionary one word at a time simply by  entering 
  258. the test-word loop as above, quitting at any convenient point. 
  259.  
  260. Obviously,  when you have more  than a handful of words to add to  the 
  261. dictionary,  it makes sense to create  a text file containing just the 
  262. words  in question,  and "feed"  it to SPELLF in "Add"  mode by typing 
  263. SPELLF <list name> -a , then Enter. 
  264.  
  265.  
  266.  
  267.  
  268.  
  269. SPELLCHECKING VS. SPELLFILTERING 
  270.  
  271. Conceptually,   there   are   two   ways  to  attack  the  problem  of 
  272. spellchecking:  You can approach it in a brute-force manner, comparing 
  273. every  word  in a file with entries in a dictionary . . . or  you  can 
  274. approach it as an "expert system" type of problem,  wherein an attempt 
  275. is  made  to catalog all known rules of spelling (and spellcheck on  a 
  276. logical basis rather than a lookup basis). The first approach -- brute 
  277. force lookup of words in an all-encompassing dictionary -- is familiar 
  278. to  anyone  who has ever used a fully  featured word  processor.  This 
  279. approach  is,  in theory,  infallible,   provided  the  dictionary  is 
  280. complete.  In the real world,  no dictionary  is ever large enough  to 
  281. approach completeness,  nor CAN a dictionary ever be foolproof, due to 
  282. the  changing  nature  of  the language.  Proper nouns  are  always  a 
  283. problem,  and new coinages are always entering  the language.  Indeed, 
  284. the  inherent "inventivity"  of English is one of its  most  endearing 
  285. characteristics. But this very  property  dooms  all  orthodox  spell-
  286. checkers to failure. 
  287.  
  288. The second approach -- that of examining the rules governing spelling, 
  289. and  constructing  a spellchecker based on those rules --  happens  to 
  290. coincide  with  the approach taken by most hyphenation programs.  Most 
  291. hyphenators  are state machines whose main operations consist of affix 
  292. analysis  and word-root parsing.  The same approach can be extended to 
  293. spellchecking.   Why not simply examine patterns of letters,  and  ask 
  294. whether  the  individual patterns are "legal constructs"  or  "illegal 
  295. constructs"  based  on  known  rules  of English spelling?  (Here,  by 
  296. patterns  we  mean  more  than  just   two-letter   combinations.)  An 
  297. adaptation of this approach is used in SPELLF. 
  298.  
  299. The  state-machine  approach has many advantages over the  brute-force 
  300. method. For one thing, it requires no bulky dictionary (which, in many 
  301. conventional  programs,  consumes  200K  or more   of  disk  space  IN 
  302. COMPACTED FORM).  For another thing, it means that,  in theory anyway, 
  303. English  words  that  don't exist yet can  be  spellchecked  properly, 
  304. because  new  coinages will always (presumably)  follow the  rules  of 
  305. English-language  letter-combining.  (That is,  it's unlikely  anybody 
  306. will  coin words that contain unpronounceable combinations like "xbjt" 
  307. or  "tqtpp.")  A  rule-based program should be able to spellcheck  new 
  308. coinages  that it has not seen before.  This is a formidable advantage 
  309. over conventional spellchecking systems. 
  310.  
  311. SPELLF  incorporates these ideas.  Plus,  it does so in ways that  are 
  312. simple, effective, and conducive to rapid program execution. 
  313.  
  314. When we say that SPELLF is a spellfilter, we mean simply that the goal 
  315. of  the  program is to filter out illogical spellings and yield  up  a 
  316. list  of  words  whose letter-combinations don't make sense  from  the 
  317. standpoint of known rules of English spelling. 
  318.  
  319.  
  320.  
  321.  
  322.  
  323. HOW THE PROGRAM WORKS (A TECHNICAL ASIDE, FOR PROGRAMMERS ONLY) 
  324.  
  325. If  you're wondering how 20,000  or more English words can fit into an 
  326. 8,192-byte  dictionary file,  consider that in 8,192  bytes there  are 
  327. 65,536 bits, each of which can represent a unique hash code. The $.DIC 
  328. file that we've been discussing so far is not really a dictionary file 
  329. in the true sense of the word, but a hash table, each one-bit entry of 
  330. which represents a 16-bit hash code derived from a four-byte substring 
  331. of  whatever  word is currently being examined.  Words less than  five 
  332. letters  long  correspond to single entries in the  hash table;  words 
  333. with five or more letters are carried in the table as multiple hashes. 
  334. A five-letter word has two hash entries;  a  six-letter word has three 
  335. hash entries; etc. 
  336.  
  337. During  runtime,  every  word in a  file is "factored  out"  into  its 
  338. constituent   hash   codes   (however   many   there  are),  and  each 
  339. corresponding hash position in the $.DIC file is checked.  If the hash 
  340. check  reveals  a  "legal"   combination of four  letters,  the  check 
  341. succeeds;  if the hash is illegal  (representing a letter  combination 
  342. not  found  in  the  table),  it fails and  the  word  is  flagged  as 
  343. "suspect." 
  344.  
  345. A  16-letter word such as "incomprehensible"  contains 13  four-letter 
  346. substrings and has 13 corresponding hash codes,  each of which must be 
  347. checked against entries in the $.DIC table.  If even one check  fails, 
  348. the  word  is flagged as suspect,  and printed to "stdout."  The  word 
  349. "incomprehensible"  must pass  all 13  checks in order to be  presumed 
  350. correctly spelled. 
  351.  
  352. Notice  that all checks are done in RAM;  the disk is not accessed  13 
  353. times when "incomprehensible"  is checked against $.DIC, because $.DIC 
  354. is captured to RAM at runtime. 
  355.  
  356. The  concept of hashing spellcheckers is not new;  McIlroy created one 
  357. for the PDP-11  (IEEE Trans. Comm. COM-30, Jan. 1982, pp. 91-99),  and 
  358. another  attempt  at such a program is discussed in CRAFTING  TURBO  C 
  359. SOFTWARE COMPONENTS & UTILITIES by Richard S.  Wiener (1988,  Wiley  & 
  360. Sons).  What is new about SPELLF  is the small size of the hash  table, 
  361. and  the  concept  of  "spellfiltering"  as  opposed  to  conventional 
  362. spellchecking  from within a text document.  No one talks about  these 
  363. programs  as filters.  But that's essentially what they are.  You  run 
  364. SPELLF on a file in order to filter out bad words -- "suspect"  words. 
  365. The spelling is never actually "checked" in the literal sense. 
  366.  
  367. One  can  argue  as to whether a 16-bit hash is adequate for  a  four-
  368. letter substring.  We start from the assumption (which is demonstrably 
  369. true)  that five bits of information will suffice to encode 26 letters 
  370. of the alphabet. We also know that 16  letters can be mapped precisely 
  371. into  four bits.  Something slightly more than four bits is needed  to 
  372. unambiguously encode 26 letters, but the process of mapping 26 letters 
  373. into four bits isn't as dangerous as it sounds,  because:  (1)  the 16 
  374. most-frequently-used  letters of the alphabet are used with very  high 
  375. frequency  indeed,  and (2)  the remaining 10  letters can be assigned 
  376. hash  positions that tend to map over known-good portions of the  hash 
  377. table.  Accordingly,  in SPELLF,  the  ASCII  table is  renumbered  to 
  378. reflect  frequency  of  usage  and best-fit   mapping,  so  that  hash 
  379. collisions  are  seldom  "fatal"  in the sense  of  allowing  a  wrong 
  380. spelling to score as "right." 
  381.  
  382. Still,  SPELLF is not perfect.  There are times when a misspelled word 
  383. is  counted as correct.  But this happens very infrequently.  (If  you 
  384. want to get a feel for this, run the program in "test" mode and try to 
  385. trick  the  dictionary  with various misspellings  of  common  words.) 
  386. Please  understand  that  we make no guarantee  of  SPELLF's  spelling 
  387. accuracy,  nor  do  we  contend that  it  is  untrickable.  SPELLF  is 
  388. imperfect -- like every spellchecker. 
  389.  
  390. What SPELLF lacks in precision, however,  it more than makes up for in 
  391. speed,  ease  of  use,  and  compactness   (to   say  nothing  of  its 
  392. adaptability to batch file technique,  redirectable output, etc.), and 
  393. on balance,  we feel the "filter"  approach is every bit as useful  in 
  394. day-to-day  usage as the orthodox big-dictionary brute-force approach. 
  395. We'd love to know what YOU think;  write to us at 578  Fairfield Ave., 
  396. Stamford,  CT 06902.  And enclose $25  for full Turbo C source  code, 
  397. ready to compile in the tiny model. 
  398.  
  399. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  400.  
  401.  
  402.  
  403.  
  404.